<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible" width="30vw" @close="close"
    :append-to-body="true">
    <el-form ref="form" label-position="left" :model="form" :rules="rules" label-width="140px">
      <el-form-item label="收发货单位名称" prop="fawudw">
        <el-input v-model.trim="form.fawudw" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="收发货单位联系人">
        <el-input v-model.trim="form.fawudwlxr" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="收发货单位联系电话">
        <el-input v-model.trim="form.fawudwdh" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="收发货单位联系地址">
        <el-input v-model.trim="form.fawudwlxfs" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model.trim="form.beizhu" type="textarea" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  insertFW,
  updateFW
} from '@/api/fawudw'


export default {
  name: 'WarehouseManagement',
  data() {
    return {
      Wzzylist: [],
      form: {

      },
      rules: {
        fawudw: [
          { required: true, trigger: 'blur', message: '请输入收发货单位名称' },
        ],
      },
      title: '',
      dialogFormVisible: false,
      zgdwlist: [],
    }
  },
  async mounted() {
    //物资分类
    this.Wzzylist = await this.$util.getWzzy()
    //主管单位
    this.zgdwlist = await this.$util.getZgdw()
  },
  created() { },
  methods: {
    async showEdit(row) {
      if (!row) {
        this.title = '新增单位'
      } else {
        this.title = '编辑单位'
        this.form = Object.assign({}, row)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let res = null
          if (this.title == '编辑单位') {
            res = await updateFW(this.form)
          } else {
            res = await insertFW(this.form)
          }
          this.$baseMessage(res.msg, 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.el-select--small {
  width: 100%;
}

.el-date-editor {
  width: 100%;
}
</style>